<template>
    <keep-alive v-if="keepAlive">
        <component :is="AsyncComponent" />
    </keep-alive>
    <component v-else :is="AsyncComponent" />
</template>
<script>
    import factory from './factory';
    export default {
        inheritAttrs: false,
        props: {
            path: {
                type: String,
                required: true,
                default: null
            },
            keepAlive: {
                type: Boolean,
                default: true
            },
            delay: {
                type: Number,
                default: 20
            },
            timeout: {
                type: Number,
                default: 2000
            }
        },
        data(){
            AsyncComponent: factory(this.path, this.delay, this.timeout);
        },
        watch: {
            path(){
                this.AsyncComponent = factory(this.path, this.delay, this.timeout);
            }
        }
    }
</script>
